:Init
@setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
@pushd %~dp0
@prompt $_
@echo off

if "%1" == "" goto Usage
if "%2" == "" goto Usage
goto CheckPaths

:Usage
@echo Encapsulates the options for copying site files.  
@echo.
@echo SYNCSITE source destination
@echo.
@echo   source      Specifies the source directory.
@echo   destination Specifies the target directory.
@echo. 
@echo Locations can be local system paths or UNC shares:
@echo.
@echo   [drive:][path][filename]
@echo   [\\server\share][\path]
@echo.
@goto End

:CheckPaths
if exists "%1" (
    @echo Source location '%1' does not exist.
    @goto End
)

:SetLogFolder
if "%DiagnosticLogs%" == "" SET DiagnosticLogs=%~dp0..\Logs
if not exist "%DiagnosticLogs%" (
	MD %DiagnosticLogs%
	if not exist "%DiagnosticLogs%" SET DiagnosticLogs=%TEMP%
 )
SET copySiteLogFile=%DiagnosticLogs%\accelerator.copySites.log

:Copy
@echo Starting file migration using the following configuration:
@echo.
@echo   "%1"
@echo               Source directory.
@echo   "%2"
@echo               Target directory.
@echo   /LOG:+"%copySiteLogFile%"
@echo               Log file (append).
@echo   /e          Copy subdirs (including empty)
@echo   /a-:R       Remove the read-only attribute.
@echo   /ZB         Copy using restartable mode; if access denied use backup mode.
@echo   /COPY:DATS  Copy data, attributes, timestamps, NTFS ACLSs
@echo   /SECFIX     Fix file security on all files, even skipped files.
@echo   /XO         Exclude older files.
@echo   /MON:1      Monitor source; run again when more than 1 changes seen.
@echo   /MOT:5      Monitor source; run again in 5 minutes Time, if changed.
@echo   /TBD        Wait for sharenames to be defined (retry error 67).
@echo
@ROBOCOPY.EXE %1 %2 /e /a-:R /ZB /COPY:DATS /SECFIX /XO /MON:1 /MOT:5 /TBD /LOG:+"%copySiteLogFile%"

REM ~~( END )~~
@echo.
@echo Completed.
@echo.
:End